<!-- head -->
{include file='public/head' /}
<!-- head -->

<!-- left -->
{include file='public/left' /}
<!-- left -->

<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            管理后台
            <small>1.0.0</small>
        </h1>
        <ol class="breadcrumb">
        </ol>
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-sm-12">
                <div class="box box-default">
                    <div class="box-header with-border">
                        <h3 class="box-title">编辑友情链接</h3>
                    </div>
                    <form class="form-horizontal" id="form" action="{:url('admin/flink/postsave','','')}">
                        <input name="id" type="hidden" id="id" value="{$id}">
                        <div class="box-body">
                            <div class="form-group">
                                <label for="webname" class="col-sm-2 control-label">网站名称</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" id="webname" name="webname" placeholder="网站名称" value="{$row.webname}">
                                    <span class="help-block" style="color:#f00;"></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="url" class="col-sm-2 control-label">链接地址</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" id="url" name="url" placeholder="链接地址" value="{$row.url}">
                                    <span class="help-block" style="color:#f00;"></span>
                                </div>
                            </div>
                        </div>
                        <div class="box-footer" style="text-align:right;">
                            <button type="button" class="btn btn-sm btn-default" id="resetForm">清空</button>&nbsp;
                            <button type="button" class="btn btn-sm btn-primary" id="saveForm">保存</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </section>
    <!-- /.content -->
</div>
<!-- /.content-wrapper -->

<script type="text/javascript">

    $(function(){

        $('#saveForm').click(function(){
            var id = $('#id').val();
            var webname = $.trim($('#webname').val());
            if (webname == '') {
                $('#webname').parents('.form-group').addClass('has-error');
                $('#webname').parent().find('.help-block').html('请输入网站名称');
                return false;
            }

            var url = $.trim($('#url').val());
            if (url == '') {
                $('#url').parents('.form-group').addClass('has-error');
                $('#url').parent().find('.help-block').html('请输入链接地址');
                return false;
            }

            $.ajax({
                url: $('#form').attr('action'),
                type: 'POST',
                data: {
                    'id': id,
                    'webname': webname,
                    'url': url,
                },
                dataType: 'JSON',
                success: function(data) {
                    if (data.status == 1) {
                        window.location.href = "{:url('admin/flink/index','','')}";
                    } else {
                        showAlert('提示', data.info, null);
                    }
                }
            });
        });

        $('#name').focus(function(){
            if ($('#name').parents('.form-group').hasClass('has-error')) {
                $('#name').parents('.form-group').removeClass('has-error');
                $('#name').parent().find('.help-block').html('');
            }
        });

    });

</script>

<!-- right -->
{include file='public/right' /}
<!-- right -->

<!-- foot -->
{include file='public/foot' /}
<!-- foot -->
